package com.shiliao.app.activity.Feedback.ui;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.shiliao.app.R;
import com.shiliao.app.activity.Feedback.presenter.FeedbackDetailPresenter;
import com.shiliao.app.activity.Feedback.view.FeedbackDetailView;
import com.shiliao.app.manager.YMUserManager;
import com.shiliao.app.weight.ActionBarView;
import com.yimei.framework.base.ui.BaseActivity;
import com.yimei.framework.util.StringUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by yinzhiqiang on 2017/9/8.
 */

public class FeedbackDetailActivity extends BaseActivity implements FeedbackDetailView {

    @BindView(R.id.action)
    ActionBarView mActionBar;

    @BindView(R.id.item_edit_content)
    EditText item_edit_content;
    @BindView(R.id.item_button_sure)
    TextView btSure;
    private FeedbackDetailPresenter feedbackDetailPresenter;
    private String userId;

    @Override
    public int getLayoutId() {
        return R.layout.activity_feedback_detail;
    }

    @Override
    public void initView() {
        super.initView();
        mActionBar.setTitles("意见反馈");
        mActionBar.getBackView().setVisibility(View.VISIBLE);
        mActionBar.setBackClick(this);
        userId = YMUserManager.getUserId(this);
        feedbackDetailPresenter = new FeedbackDetailPresenter(this);
        item_edit_content.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (StringUtils.containsEmoji(editable.toString())) {
                    showToast("请不要输入表情字符!");
                    return;
                }
            }
        });
    }

    @OnClick(R.id.item_button_sure)
    public void comfirmFeedback() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                String feedbackContent = item_edit_content.getText().toString().trim();
                if (TextUtils.isEmpty(feedbackContent)) {
                    showToast("请输入反馈内容");
                }
                feedbackDetailPresenter.requestSuggstion(userId, feedbackContent);
            }
        });
    }


    @Override
    public void backFeedback() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                showToast("感谢您的反馈");
                //toMainActivity(MainActivity.POSITON_FEEDBACK);
                FeedbackDetailActivity.this.finish();
            }
        });
    }
}
